package com.hqyj.shop.config;

import com.hqyj.shop.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.Schedules;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 项目:shop-admin-240701
 * 描述:
 * 时间:2024/10/21 15:50
 * 作者:admin
 * 版本:1.0
 **/
@Component
@EnableScheduling
@Slf4j
public class OrderScheduling {

    @Autowired
    RedisTemplate<String,Object> redisTemplate;

    @Autowired
    OrderInfoService service;
    //处理队里
    @Scheduled(fixedDelay = 5000)
    public void create(){
        Object obj = redisTemplate.opsForList().rightPop("order");
        if(obj!=null){
            log.info("开始消费");
            Map<String,Object> map =(Map<String,Object>) obj;
            service.updateOrder(map.get("no").toString(),map.get("subject").toString());
        }else{
            log.info("队列消费完了");

        }
    }
}
